######################################################################
#
#    Author :  Ao Zhang
#    E-mail :  nlp410.cn@gmail.com
#
#    Date   :  Apr. 10, 2012
#
#    Description :
#
######################################################################

class aligned_words_info:
	'''
	the alignment infomation from one language to the other
	'''
	words           = []		# words in one of the languages
	alignment_count = []		# how many times that are aligned with the other language
	align_with      = [[]]		# which words are aligned with the corresponding one in this array

class words_alignment:
	source_lang_info = aligned_words_info()
	dest_lang_info = aligned_words_info()

	def build_alignment( self, src_sentence, dst_sentence, s2d_alignment ):
		self.source_lang_info.words = src_sentence.split( word_sep )
		self.dest_lang_info.words = dst_sentence.split( word_sep )
		aligned_table = s2d_alignment.split( word_sep )

		src_words_count = len( self.source_lang_info.words )
		dst_words_count = len( self.dest_lang_info.words )

		self.source_lang_info.align_with = [[None]] * src_words_count
		self.source_lang_info.alignment_count = [0] * src_words_count
		self.dest_lang_info.align_with = [[None]] * dst_words_count
		self.dest_lang_info.alignment_count = [0] * dst_words_count

		for altb in align_table:
			s_no, d_no = altb.split( '-' )

			if s_no >= src_words_count or d_no >= dst_words_count:
				return False

			self.source_lang_info.alignment_count[ s_no ] += 1
			self.source_lang_info.align_with[ s_no ].append( d_no )
			self.dest_lang_info.alignment_count[ d_no ] += 1
			self.dest_lang_info.align_with[ d_no ].append( s_no )

		return True

